package com.whfc.fmam.service.impl;

import com.whfc.fmam.dao.FmamUnitMapper;
import com.whfc.fmam.entity.bo.FmamUnit;
import com.whfc.fmam.entity.dto.SyncFmamUnitDTO;
import com.whfc.fmam.map.UnitMap;
import com.whfc.fmam.service.FmamUnitService;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/10/10 11:02
 */
@DubboService(interfaceClass = FmamUnitService.class, version = "1.0.0")
public class FmamUnitServiceImpl implements FmamUnitService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FmamUnitMapper fmamUnitMapper;

    @Autowired
    private UnitMap unitMap;

    @Override
    public List<SyncFmamUnitDTO> getAllFmamUnitList() {
        logger.info("查询所有计量单位");
        List<FmamUnit> unitList = fmamUnitMapper.selectAllUnitDTOList();
        List<SyncFmamUnitDTO> unitDTOList = unitList.stream().map(unit -> unitMap.to(unit)).collect(Collectors.toList());
        return unitDTOList;
    }
}
